#include "instrument.h"

Instrument::Instrument()
{
}

QList < Position > Instrument::getPositions(Note nt)
{
    int l = positions.length();
    QList < Position > pos_list;
    Position pos;

    if(positions.isEmpty()) return pos_list;

    for(int i = 0; i < l; i++) {
        pos = positions.at(i);
        if(pos.getNote() == nt) {
            pos_list.append(pos);
        }
    }
    return pos_list;
}

QList < Position > Instrument::getPositions(QString bps_name)
{
    int l = positions.length();
    QList < Position > pos_list;
    Position pos;

    if(positions.isEmpty()) return pos_list;

    for(int i = 0; i < l; i++) {
        pos = positions.at(i);
        if(bps_name == pos.getName()) {
            pos_list.append(pos);
        }
    }
    return pos_list;
}

QList < Position > Instrument::getPositions(BasePosition bps)
{
    return getPositions(bps.getName());
}

// Convert from readed note for instrument to real note
Note Instrument::getRealNote(Note readed_note)
{
    if( !isTransposingInstrument() ) return readed_note;
    else return readed_note.transpose(getTranposeNote(), getTonalityNote());
}

// Convert from real note for instrument to readed not
Note Instrument::getReadedNote(Note real_note)
{
    if( !isTransposingInstrument() ) return real_note;
    else return real_note.transpose(getTonalityNote(), getTranposeNote());
}
